﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [steve].[spSteve_UpdateSiteUrl] 
	-- Add the parameters for the stored procedure here
	@SiteUrlId uniqueidentifier,
	@StartDate datetime2(7),
	@EndDate datetime2(7),
	@IsSecure bit,
	@IgnoreQueryString bit,
	@PageTitle nvarchar(200),
	@PageMetaDescription nvarchar(200),
	@PageMetaKeywords nvarchar(200),
	@RevisionDate datetime2(7),
	@RevisionMembershipId uniqueidentifier,
	@RevisionComment nvarchar(400)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	DECLARE @revision INT
	
	SELECT @revision = MAX(RevisionNumber) + 1
	FROM SiteUrlRevision
	WHERE SiteUrlId = @SiteUrlId

    -- Insert statements for procedure here
	INSERT INTO SiteUrlRevision (SiteUrlId
		, RevisionNumber
		, StartDate
		, EndDate
		, IsSecure
		, IgnoreQueryString
		, PageTitle
		, PageMetaDescription
		, PageMetaKeywords
		, RevisionDate
		, RevisionMembershipId
		, RevisionComment)
	VALUES (@SiteUrlId
		, @revision
		, @StartDate
		, @EndDate
		, @IsSecure
		, @IgnoreQueryString
		, @PageTitle
		, @PageMetaDescription
		, @PageMetaKeywords
		, @RevisionDate
		, @RevisionMembershipId
		, @RevisionComment)
		
	UPDATE SiteUrl
	SET LatestRevisionNumber = @revision
	WHERE SiteUrlId = @SiteUrlId
	
	SELECT @revision as LatestRevisionNumber
		
END
